//计算方法
#include"Protocol.hpp"
#include<string>
enum{
    Div_Err=1,
    Mode_Err,
    Other_Oper
};
class Servercal
{
    public:
    Servercal()
    {

    }
    Response CalculatorHandler(const Request&rq)
    {
        Response spon(0,0);
        switch(rq.op_)
        {
            case '+':spon.result_=rq.x_+rq.y_;
            break;
            case '-':spon.result_=rq.x_-rq.y_;
            break;
            case '*':spon.result_=rq.x_*rq.y_;
            break;
            case '/':if(rq.y_==0){spon.code_=Div_Err;}else spon.result_=rq.x_/rq.y_;
            break;
            case '%':if(rq.y_==0){spon.code_=Mode_Err;}else spon.result_=rq.x_%rq.y_;
            break;
            default:
            spon.code_=Other_Oper;
            break;

        }
        return spon;
    }
    std::string Calculator( std::string& package)
    {
        std::string content;
        bool r=Decode(package,&content);
        if(!r)return "";
        Request rq;
      r=  rq.Deserialize(content);
      if(!r)return "";
      Response rp=CalculatorHandler(rq);
      
      r=rp.Serialize(&content);
      if(!r)return "";
      content=Encode(content);
        return content;
    }
    ~Servercal()
    {

    }
};